<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0">
    <title>来拍车App-12.12大波福利来袭</title>
    <link rel="stylesheet" href="{:get_style_cdnurl()}app/css/common.css">
    <link rel="stylesheet" href="{:get_style_cdnurl()}app/activities/1212/1212.css">
</head>
<body class="share-bg">
<div class="pic"><img src="{:get_style_cdnurl()}app/activities/1212/01-1.jpg" alt=""></div>
<div class="pic"><img src="{:get_style_cdnurl()}app/activities/1212/02-1.jpg" alt=""></div>
<div class="pic"><img src="{:get_style_cdnurl()}app/activities/1212/03.jpg" alt=""></div>
<div class="pic pic04">
    <img src="{:get_style_cdnurl()}app/activities/1212/04-1.jpg" alt="">
    <div class="form-wrapper">
        <!-- <form action=""> -->
        <div class="label">请输入您的手机号码:</div>
        <div class="input-data">
            <input type="text" name="phone" id="phone"><button id="send_code_btn" onclick="send_code(this)">获取验证码</button>
        </div>
        <div class="label">输入验证码:</div>
        <div class="input-data">
            <input type="text" name="code" id="code">
        </div>
        <span id='a' class="btn">帮砍</span>
        <!-- </form> -->
    </div>
</div>

<script type="text/javascript" src="{:get_style_cdnurl()}app/js/jquery.min.js"></script>
<script type="text/javascript">
    $(document).ready(function() {
        $("img").on("click", function(e){
            e.preventDefault();
        });

        $(".form-wrapper .btn").on("click", function(){

            var phone = $('#phone').val();
            var code = $('#code').val();

            if($.trim(phone)==''){
                showTip('很遗憾', '请先输入手机号！','');
                return ;
            }
            if(!phone.match(/^1\d{10}$/)) {
                showTip('很遗憾', '请输入正确的手机号！','');
                return ;
            }
            if($.trim(code)==''){
                showTip('很遗憾', '请先输入短信验证码！','');
                return ;
            }

            var obj = {
                'aid':'{$Think.request.aid}',
                'param':'{$Think.request.param}',
                'invite_code':'{$Think.request.invite_code}',
                'phone':phone,
                'code':code
            }

            $(".form-wrapper .btn").text('处理中..');

            $.post('{$Think.const.WEB_URL}Dealer/do_cutdown',obj,function(res){
                if(res.code=='200'){
                    $(".form-wrapper .btn").unbind('click');
                    $(".form-wrapper .btn").text('已帮砍');
                    showTip("恭喜您", "已成功帮砍", "", res.data.money);
                }else{
                    showTip("很遗憾", res.msg, "");
                    $(".form-wrapper .btn").text('帮砍');
                }
            },'json');
        });

        var exception = '{$error}';
        if(exception){
            showTip('很遗憾',exception,'');
        }

    });


    function send_code(obj){
        //输入有效性验证
        var phone = $('#phone').val();
        if($.trim(phone)==''){
            showTip('很遗憾', '请先输入手机号！','');
            return ;
        }
        if(!phone.match(/^1\d{10}$/)) {
            showTip('很遗憾', '请输入正确的手机号！','');
            return ;
        }

        //短信重发倒计时
        var countdown=60;
        function settime(obj){
            if (countdown == 0) {
                obj.removeAttribute("disabled");
                obj.innerText="获取验证码";
                countdown = 60;
                return;
            } else {
                obj.setAttribute("disabled", true);
                obj.innerText="重新发送(" + countdown + ")";
                countdown--;
            }
            setTimeout(function() {settime(obj) } ,1000);
        }

        //发送短信验证码
        var obj_param = {
            'aid':'{$Think.request.aid}',
            'param':'{$Think.request.param}',
            'invite_code':'{$Think.request.invite_code}',
            'phone':phone
        }
        $.post('{$Think.const.WEB_URL}Dealer/send_verify_code',obj_param,function(res){
               if(res.code=='200'){
                   showTip('恭喜您', '验证码发送成功，','请查询短信获得验证码。');
                   settime(obj);
               }else{
                   showTip('很遗憾', res.msg,'');
               }
        },'json');
    }

    function showTip(title, msg1, msg2, money){
        var tempStr = money ? ("<p>"+msg1+"<strong>"+money+"元</strong>") : ("<p>"+msg1+"</p><p>"+msg2+"</p>");
        var htmlStr = "<div class='pop-wrapper'>"
                +"<div class='pop-box'>"
                +"<div class='title'>"+title+"</div>"
                +"<div class='content'>"+tempStr+"</div>"
                +"<div class='btn'>确定</div>"
                +"</div>"
                +"</div>";
        $("body").append(htmlStr);
        $(".pop-wrapper").fadeIn(200);
        $(".pop-wrapper div.btn").on("click", function(){
            $(".pop-wrapper").fadeOut(200).remove();
        });
    }

</script>

</body>
</html>